//package com.qinglei.recoup.hmp.controller;
//
//
//import com.qinglei.recoup.common.utils.HttpXmlClient;
//import net.sf.json.JSONObject;
//import org.apache.commons.lang.StringUtils;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.util.HashMap;
//import java.util.Map;
//
//@RestController
//@RequestMapping("wechat/")
//public class WxController {
//    //https://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=jsapisign
//    @Value("${wx.appId}")
//    private String appId;
//    @Value("${wx.appSecret}")
//    private String appSecret;
//
//
//    @GetMapping("/getSignature")
//    public Map<String, Object> getSignature(String url){
//        Map<String, Object> reseltMap = new HashMap<>();
//        if(StringUtils.isEmpty(url)){
//            reseltMap.put("code",500);
//            reseltMap.put("msg","url不能为空");
//            return reseltMap;
//        }
//        String client_credential = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+appId+"&secret="+appSecret;
//        String body = HttpXmlClient.get(client_credential);
//        JSONObject  json = JSONObject.fromObject(body);
//        String ACCESS_TOKEN = (String) json.get("access_token");
//        String accessTokenURl = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token="+ACCESS_TOKEN+"&type=jsapi";
//        String body1 = HttpXmlClient.get(accessTokenURl);
//        String jsapi_ticket = (String) JSONObject.fromObject(body1).get("ticket");
//        Map<String,String> data = new HashMap<>();
//        // 注意 URL 一定要动态获取，不能 hardcode
//        Map<String, String> ret = HttpXmlClient.sign(jsapi_ticket, url);
//        for (Map.Entry entry : ret.entrySet()) {
//            data.put(entry.getKey()+"",entry.getValue()+"");
//        }
//        data.put("appId",appId);
//        reseltMap.put("code",200);
//        reseltMap.put("msg","成功！");
//        reseltMap.put("data",data);
//        return reseltMap;
//    };
//
//
//    //String accessUrl = String.format("https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code", appId, secret, code);
//    //
//
//}
